﻿using BlazorLearn.Shared.Models;
using BlazorLearn.Shared.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;

namespace BlazorLearn.Shared.Pages;
partial class Login
{
    LoginViewModel Model { get; set; } = new();

    [Inject]IAuthenticationService AuthenticationService { get; set; }

    [Inject]NavigationManager NavigationManager { get; set; }   

    async Task SubmitAsync(EditContext context)
    {
        //Server or WebAssembly?

        try
        {
            await AuthenticationService.SignInAsync(Model);
            //登录成功
            NavigationManager.NavigateTo("/");
        }
        catch(InvalidOperationException ex)
        {
            //登录失败
            throw ex;
        }
    }
}
